package Test02;
import java.util.Scanner;
public class MaxSubArraySum {
    public static int maxSubArray(int[] nums) {
        int maxSoFar = nums[0];
        int currMax = nums[0];

        for (int i = 1; i < nums.length; i++) {
            currMax = Math.max(nums[i], currMax + nums[i]);
            maxSoFar = Math.max(maxSoFar, currMax);
        }

        return maxSoFar;

    }

    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        int number=Integer.parseInt(sc.next());

        //number表示数组长度
        int[] num =new int[number];

        //依次输入数组元素
        for(int i=0;i<number;i++){
            num[i]=(int)sc.nextInt();
        }
        System.out.println(maxSubArray(num));
    }
}
